package com.spider.spiderflowable.business.controller;

import com.spider.spiderflowable.common.ResponseEntity;
import com.spider.spiderflowable.core.service.SpiderProcessDeploymentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.flowable.engine.repository.Deployment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 流程部署接口
 *
 * @author xiong.bo
 * @version 1.0
 * @date 2022/12/9 8:51 下午
 */

@Tag(name = "流程部署接口")
@RequestMapping("/api/deployment")
@RestController
public class SpiderProcessDeploymentController {

    @Autowired
    private SpiderProcessDeploymentService deploymentService;

    @Operation(summary = "部署流程-根据资源相对路径（一般用来本地测试）")
    @PostMapping("/release-resource")
    public ResponseEntity<Deployment> exportUserData(String classpathResource, String processKey,
        String processName, Long tenantId) {
        return ResponseEntity.success(
            deploymentService.createDeployment(classpathResource, processKey, processName,
                tenantId));
    }

    @Operation(summary = "部署流程-根据流程文件URL")
    @PostMapping("/release-url")
    public ResponseEntity<Deployment> createDeployment(String processName, String processUrl, Long tenantId) {
        return ResponseEntity.success(deploymentService.createDeployment(processName, processUrl, tenantId));
    }


}
